	ORG $0000
SUM	FCB $00

START	EQU $FF00
	ORG $FF00
NODE1	FCB $FF,$10,$FF,$20,$07
	ORG $FF10
NODE2	FCB $FF,$30,$FF,$40,$05
	ORG $FF20
NODE3	FCB $FF,$50,$FF,$60,$03
	ORG $FF30
NODE4	FCB $00,$00,$00,$00,$02
	ORG $FF40
NODE5	FCB $FF,$70,$00,$00,$01
	ORG $FF50
NODE6	FCB $00,$00,$00,$00,$05
	ORG $FF60
NODE7	FCB $00,$00,$00,$00,$0A
	ORG $FF70
NODE8	FCB $00,$00,$00,$00,$06

	ORG $E000

BINTRAV	TSX
	LDY 2,X
	LDAA #0
	STAA SUM
	BRA ADDUP
	
LEFT	TSY
	LDX 2,Y
	LDY 0,X
	BRA ADDUP

RIGHT	TSY
	LDX 2,Y
	LDY 2,X
	BRA ADDUP

ADDUP	CPY #0
	BEQ RECURSE
	PSHY
	JSR LEFT
	JSR RIGHT
	TSY
	LDX 0,Y
	LDAA 4,X
	ADDA SUM
	STAA SUM
	PULX
RECURSE	RTS

	ORG $C000

	LDX #START
	PSHX
	JSR BINTRAV
LOOP	BRA LOOP
